package com.ccb.course.service.impl;

import com.ccb.course.entity.Course;
import com.ccb.course.entity.StudentCourse;
import com.ccb.course.mapper.CourseMapper;
import com.ccb.course.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-11-02
 */
@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> selectCourseByNo(int no) {
        return courseMapper.selectCourseByNo(no);
    }

    @Override
    public int selectedCourse(String nos, int sno) {
        String[] strs = nos.split(",");
        List<StudentCourse> list = new ArrayList();
        for (int i = 0; i < strs.length; i++) {
            StudentCourse sc = new StudentCourse();
            sc.setSno(sno);
            sc.setCno(Integer.parseInt(strs[i]));
            list.add(sc);
        }
        return courseMapper.selectedCourse(list);
    }

    @Override
    public List<Course> selectSelectedCourseByNo(int sno) {
        return courseMapper.selectSelectedCourseByNo(sno);
    }
}
